
<template>
  <view class="picker-view">
    <view class="picker-view__pane">
      <text @click="emits('close')">取消</text>
      <text @click="confirmSite">确定</text>
    </view>

    <picker-view
      class="pick-view__group"
      :value="multiIndex"
      @change="provincesChange"
    >
      <picker-view-column indicator-class="item_active">
        <view
          v-for="(item, index) in provinces"
          :key="index"
          class="picker-item"
          >{{ item.province }}</view
        >
      </picker-view-column>
      <picker-view-column>
        <view v-for="(item, index) in citys" :key="index" class="picker-item">{{
          item.city
        }}</view>
      </picker-view-column>
      <picker-view-column>
        <view v-for="(item, index) in areas" :key="index" class="picker-item">{{
          item.area
        }}</view>
      </picker-view-column>
    </picker-view>
  </view>
</template>
  
  <script setup>
import { defineProps, ref, defineEmits } from "vue";
import addressJson from "@/utils/addressLib";

const emits = defineEmits(["confirm", "close"]);
const props = defineProps({
  product: {
    type: Object,
    default: () => ({}),
  },
});

const provinces = ref(addressJson.addressList || []); // 省
const citys = ref(addressJson.addressList[0].cityList || []); // 市
const areas = ref(addressJson.addressList[0].cityList[0].areaList || []); // 区

const multiIndex = ref([0, 0, 0]);

const provincesChange = (e) => {
  console.log(e);
  multiIndex.value = e.detail.value;
  citys.value = provinces.value[multiIndex.value[0]].cityList;
  areas.value = citys.value[multiIndex.value[1]].areaList;
};

const confirmSite = () => {
  emits("confirm", [
    provinces.value[multiIndex.value[0]].province,
    citys.value[multiIndex.value[1]].city,
    areas.value[multiIndex.value[2]].area,
  ]);
  emits('close')
};
</script>
  
  <style lang="less" scoped>
@import "@/static/css/theme.less";

.picker-view {
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  background-color: #fff;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  bottom: 0rpx;
  left: 0rpx;
}

.picker-item {
  line-height: 70rpx;
  margin-left: 5rpx;
  margin-right: 5rpx;
  text-align: center;
}

.picker-view__pane {
  height: 100rpx;
  width: 100%;
  padding: 20rpx 32rpx;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-sizing: border-box;
}

.picker-view__pane text {
  font-size: 30rpx;
}

.picker-view__pane text:first-of-type {
  color: #9a9a9a;
}

.picker-view__pane text:last-of-type {
  color: @primary-color;
}

.pick-view__group {
  width: 96%;
  height: 450rpx;
}
</style>
  